#ifndef _DECODERCOMMUNICATOR_H_
#define _DECODERCOMMUNICATOR_H_

#include <queue>
#include <string>

#include "gmpxx.h"
#include "online-certifier/util/typeDefines.hh"
#include "communicatorUtil.hh"



class decoderCommunicator {
    public:
        decoderCommunicator(int decoder_port, char* dataProxy_addr, int dataProxy_port);
        e_status runDecoderServer(); //wait for the front end to connect
        e_status readFromFrontend(size_t* k, size_t* max_errors);
        e_status writeToFrontend(integer res, size_t errors);
        e_status writeEndOfResultToFrontend();
        e_status connectToDataProxy();
        e_status readFromDataProxy(fixedBitSizeInteger* residue, fixedBitSizeInteger* prime);
        e_status terminate();
        void resetCounter(){result_counter = 0;}

    private:
        e_status terminateDataProxy();
        int decoderPort, dataProxyPort;
        char dataProxyAddr[12]; //ip address
        int sock;//decoder socket
        int connected; //socket connected to frontend
        int dataProxySock;
        char send_data [DECODER_BUFFER_SIZE] , recv_data[DECODER_BUFFER_SIZE];
        std::queue < std::string > resultQueue;
        std::queue < std::string > commandQueue;

        size_t result_counter;
};
#endif
